package cn.zhaotianen.retrofit.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import cn.zhaotianen.retrofit.app.GlobalContext;

/**
 * <p/>
 * <pre>
 * ***************************************************************
 *  Package: cn.zhaotianen.retrofit.utils
 *  Description:
 *  @since 1.0.0
 *  @author zhaotianen
 *  @date 16/7/2
 *  @time 20:02
 * ***************************************************************
 * </pre>
 */
public class NetworkUtils {

    public static boolean networkIsAvailable(Context context) {
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (null != connectivity) {
            NetworkInfo info = connectivity.getActiveNetworkInfo();
            if (null != info && info.isConnected()) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
        return false;
    }

}
